<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>Test Ajax File Upload</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/ajaxfileupload.js"></script>
<script type="text/javascript">
	$(function() {

		$("#but").click(function() {
			
			$("#t_loading").ajaxStart(function(){
				$(this).show();
			}).ajaxComplete(function(){
				$(this).hide();
			});
			
			var elementIds=["flag"]; //flag为id、name属性名
			$.ajaxFileUpload({
			
				url:'test/AjaxUpload.action',
				type:'post',
				secureuri: false, //一般设置为false
				fileElementId: 'file1', // 上传文件的id、name属性名
				dataType:'text',
				elementIds:elementIds,
				success:function(data,status){
					alert(data);
				},
				error:function(data,status,e){
					alert(e);
				}
			});
			
		});

	});
</script>
</head>

<body style="text-align: center;">

	<div id="wait_loading" style="padding: 50px 0 0 0;display:none;">
		<div style="width: 103px;margin: 0 auto;">
			开始不显示、、
			<img src="<%=path%>/images/loading.gif" />
		</div>
		<br></br>
		<div style="width: 103px;margin: 0 auto;">
			<span>请稍等...</span>
		</div>
		<br></br>
	</div>

	<div style="width: 50%">
		选择文件：<input type="file" id="file1" name="file">&nbsp;
		<input type="hidden" id="flag" name="flag" value="ajax文件上传"/>
		<input type="button" id="but" value="上传">
	</div>
	
	<form action="test/AjaxUpload.action" method="post" enctype="multipart/form-data">
		用户名：<input type="text" name="userName" /><br/>
		上传文件：<input type="file" name="file1" /><br>
		<input type="submit" value="上传">
	</form>

	hahahah
</body>
</html>
